From 37d3712dc7e1e91c49733a8ad40d4cc719b1e3d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Elio=20Petten=C3=B2?= Date: Sat, 25 Jan 2020 11:05:54 +0000 Subject: freestyle: raise exceptions if a command returned an error state. This includes both the classic "unknown message type" error, and the Libre 2 encryption error state. --- glucometerutils/support/freestyle.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/glucometerutils/support/freestyle.py b/glucometerutils/support/freestyle.py index ea2ac14..c94a92b 100644 --- a/glucometerutils/support/freestyle.py +++ b/glucometerutils/support/freestyle.py @@ -132,6 +132,13 @@ class FreeStyleHidDevice(hiddevice.HidDevice): if message_type == 0x22 and message_length == 1: return self._read_response() + if message_type == 0x30 and message_content == b'\x85': + raise exceptions.CommandError('Invalid command') + + if message_type == 0x33 and message_content == b'\x15': + raise exceptions.CommandError( + 'Device encryption initialization failed.') + # hidapi module returns a list of bytes rather than a bytes object. return (message_type, bytes(message_content)) -- cgit v1.2.3